import java.util.Scanner;

//求斐波那契数列的第n项。(迭代实现)
public class Question4 {

    public static void main(String[] args) {

        int n;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数：");
        n = sc.nextInt();

        System.out.println("求斐波那契数列的第"+n+"项为："+Fibonacci(n));



    }

    public static int Fibonacci(int n){

        int a = 1;
        int b = 1;
        int c = 0;

        int i = 0;

        while(i <= n){

            if(n <= 2){

                c = 1;
                break;
            }

            if(i <= 2){

                c = 1;



            }else {

                c = a + b;
                a = b;
                b = c;

            }

            i++;//优化，写在分支语句if else中，要写两次

        }

        return c;
    }



}
